package neutron

import (
	. "gddgame.cc/galaxy/common/dsl/web"
	"gddgame.cc/galaxy/project/neutron/neutron/controller"
	"gddgame.cc/galaxy/server/composer"
	"gddgame.cc/galaxy/server/web"
)

func UnitHandle(path string, builder composer.Builder, router web.Router) {
	r := NewSwaggerRouter(path, builder, router, &SwaggerRouterConfig{
		Info: SwaggerInfo{
			Title: "",
		},
	})
	web.Restful(router)

	r.Post("/start", Swagger{
		Controller: controller.StartUnit,
		Params: []Param{
			{Name: "name", In: Body, Required: true},
			{Name: "target", In: Body, Required: true},
			{Name: "force", In: Body, Type: Boolean, Default: false},
		},
		Response: ApiResponse,
	})

	r.Put("/restart", Swagger{
		Controller: controller.RestartUnit,
		Params: []Param{
			{Name: "name", In: Body, Required: true},
			{Name: "force", In: Body, Type: Boolean, Default: false},
		},
		Response: ApiResponse,
	})

	r.Put("/stop", Swagger{
		Controller: controller.StopUnit,
		Params: []Param{
			{Name: "name", In: Body, Required: true},
		},
		Response: ApiResponse,
	})

	r.Get("/show/{name}", Swagger{
		Controller: controller.ShowUnit,
		Params: []Param{
			{Name: "name", In: Path},
		},
		Response: ApiResponse,
	})

	r.Get("/showAll", Swagger{
		Controller: controller.ShowAllUnit,
		Response:   ApiResponse,
	})
}
